//
//  VEAssionIntrodTableViewCell.m
//  VEMoneyPorject
//
//  Created by BlueWind on 2018/9/13.
//  Copyright © 2018年 陈建. All rights reserved.
//

#import "VEAssionIntrodHeadTableViewCell.h"

@implementation VEAssionIntrodHeadTableViewCell

{
    UIImageView *_imageView;
    
    UIImageView *_assionHeadImage;
    
    UILabel *_assionTitle;
    
    
    NSMutableArray *arr;
    
}

/** 返回循环利用的cell */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self loadDefaultSetting];
    }
    return self;
}

/** 加载默认UI元素和需要的数据 */
- (void)loadDefaultSetting {
    
    arr = [NSMutableArray new];
    
    _imageView = [UIImageView new];
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    _imageView.clipsToBounds = YES;
    [self.contentView addSubview:_imageView];
    [_imageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(150);
    }];
    _imageView.image = [UIImage imageNamed:@"pxa"];
    
    _assionHeadImage = [UIImageView new];
    [self.contentView addSubview:_assionHeadImage];
    [_assionHeadImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self->_imageView.mas_bottom);
        make.centerX.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    [_assionHeadImage layerBorderWithWidth:2 borderColor:[UIColor whiteColor]];
    [_assionHeadImage setLayerCornerRadius:40];
    _assionHeadImage.image = [UIImage imageNamed:@"First_PlaceHolder"];
    
    _assionTitle = [UILabel new];
    [self.contentView addSubview:_assionTitle];
    [_assionTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_assionHeadImage.mas_bottom).offset(GAP8);
        make.centerX.equalTo(self->_assionHeadImage);
    }];
    _assionTitle.font = kFont(30);
    _assionTitle.text = @"VE官方社群";
    
    NSArray *buttonTitleArray = @[@"主题",@"点赞",@"评论"];
    NSArray *buttonImageArray = @[@"主题",@"超级赞1",@"评论"];
    
    for (NSInteger index = 0; index < buttonImageArray.count; index ++) {
        RankButton *button = [RankButton new];
        [self.contentView addSubview:button];
        button.type = buttonTypePicTop;
        button.picTileRange = 5;
        [button mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self->_assionTitle.mas_bottom).offset(GAP8);
            make.left.equalTo(self.contentView).offset((SCREEN_WIDTH - 165)/4 * (index + 1) + (55 * index));
            make.size.mas_equalTo(CGSizeMake(55, 80));
        }];
        [button setTitle:buttonTitleArray[index] forState:(UIControlStateNormal)];
        [button setImage:[UIImage imageNamed:buttonImageArray[index]] forState:(UIControlStateNormal)];
        button.userInteractionEnabled = NO;
        [arr addObject:button];
    }
    
    UIView *line = [UIView new];
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(GAP8);
    }];
    line.backgroundColor = [UIColor colorWithHexString:kCommonBgColor];
    
}

- (void)setModel:(VEAssionModel *)model {
    _model = model;
    [_assionHeadImage setImageWithUrlString:model.COMMUNITYPHOTO palceHolderImage:[UIImage imageNamed:@"First_PlaceHolder"]];
    _assionTitle.text = model.COMMUNITYNAME;

    UIButton *button1 = arr[0];
    UIButton *button2 = arr[1];
    UIButton *button3 = arr[2];
    
    [button1 setTitle:[NSString stringWithFormat:@"%ld",model.zhuti] forState:(UIControlStateNormal)];
    [button2 setTitle:[NSString stringWithFormat:@"%ld",model.zan] forState:(UIControlStateNormal)];
    [button3 setTitle:[NSString stringWithFormat:@"%ld",model.pinglun] forState:(UIControlStateNormal)];

    
}


@end
